<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
	<div class="container">
		<div class="navbar-header">
			<a class="navbar-brand" href="/home/homeGoods.html" style="font-size: 25px">校园二手交易平台</a>
		</div>

		<div id="navbar" class="navbar-collapse collapse">
			<!--未登录-->
			<div id="out" >
				<ul  class="nav navbar-nav">
					<li><a href="/">首页</a></li>
				</ul>

				<ul class="nav navbar-nav navbar-right">
					<li><a href="/home/login.html" >登录</a></li>
					<li><a href="/home/register.html" >注册</a></li>

				</ul>
			</div>

			<!--已登录-->
			<div id="in" style="display: none" >
				<ul  class="nav navbar-nav">
					<!--				<c:choose>-->
					<!--					<c:when test="${sessionScope.user != null}">-->
					<!--						<li><a href="<c:url value="/"/>">首页</a></li>-->
					<li><a href="/">首页</a></li>
					<!--						<li><a target="_blank"-->
					<!--							href="<c:url value="/user/userProfile"/>">我的</a></li>-->
					<li><a target="_blank"
						   href="/user/userProfile.html">我的</a></li>

					<!--						<li><a target="_blank"-->
					<!--							href="<c:url value="/goods/publishGood" />">发布</a></li>-->
					<li><a target="_blank"
						   href="/goods/publishGood.html">发布</a></li>
					<!--					</c:when>-->
					<!--					<c:otherwise>-->
					<!--						<li><a href="<c:url value="/"/>">首页</a></li>-->
					<!--					</c:otherwise>-->
					<!--				</c:choose>-->
				</ul>

				<ul class="nav navbar-nav navbar-right">
					<!--				<c:choose>-->
					<!--					<c:when test="${sessionScope.user != null}">-->
					<!--						<li><img-->
					<!--							src="<c:url value="${sessionScope.user.getPhotoUrl()}"/>"-->
					<!--							height="50px" width="50px"></li>-->
					<li><img
							id="headerMyImage"
							src=""
							height="50px" width="50px"></li>

					<!--						<li><a target="_blank"-->
					<!--							href="<c:url value="/user/userProfile"/>">${sessionScope.user.getName()}</a></li>-->
					<li><a id="headerMyName"
						   target="_blank"
						   href="/user/userProfile.html"></a></li>

					<!--						<li><a href="<c:url value="/logout?logout=true"/>">退出</a></li>-->
					<li><a onclick="logout()">退出</a></li>
					<!--					</c:when>-->
					<!--					<c:otherwise>-->
					<!--						<li><a href="<c:url value="/login" />">登录</a></li>-->
					<!--						<li><a href="<c:url value="/register" />">注册</a></li>-->
					<!--					</c:otherwise>-->
					<!--				</c:choose>-->
				</ul>
			</div>
		</div>
	</div>
</nav>
<div class="col-md-12" style="height: 70px"></div>
<script>
	function logout(){
		$.ajax({
			url: "/user/logout",
			success:function(data){
				window.location.href = "/home/homeGoods.html";
			}
		})
		window.userInfo=null;
	}
	function ajax_send(func){
		window.userInfo={
			id:'',
			picture:'defaultProfileImage.jpg',

		};
		$.ajax({
			type:"POST",
			url:"/user/preInfo",
			contentType: "application/json;charset=utf-8",
			data:JSON.stringify(123),
			success:function(data){
				// alert("chenggong ");
				// console.log(userInfo.id);
				// console.log(data);
				if(data.code==20000){
					document.getElementById("out").style.display="none";//隐藏
					document.getElementById("in").style.display="";//显示
					$('#headerMyImage').attr("src",  "https://yilutangping.oss-cn-shenzhen.aliyuncs.com/userProfileImage/" + data.data.picture);
					$('#headerMyName').html(data.data.nickName);
					func.call(this,data);
					window.userInfo=data.data;
				}

			}
		});
	}
	// 进入网页自动发送ajax
	(function(){
		ajax_send(function(res){
		});
	})();
</script>
<html/>
</body>
</html>